package com.atguigu.union;

import java.util.Random;

public class TestUF {

    public static double testUF(UF uf,int m){
        long startTime=System.nanoTime();
        int size=uf.getSize();
        Random random=new Random();
        for (int i = 0; i < m; i++) {
            int a=random.nextInt(size);
            int b=random.nextInt(size);
            uf.unionElements(a,b);
        }
        for (int i = 0; i < m; i++) {
            int a=random.nextInt(size);
            int b=random.nextInt(size);
            uf.isConnected(a,b);
        }
        long endTime=System.nanoTime();
        return (endTime-startTime)/1000000000.0;

    }

    public static void main(String[] args) {
        int size=10000000;
        int m=10000000;
        UnionFind1 unionFind1=new UnionFind1(size);
        double time = testUF(unionFind1, m);
        System.out.println("UnionFind1 : "+time+" s");
        UnionFind2 unionFind2=new UnionFind2(size);
        double time2 = testUF(unionFind2, m);
        System.out.println("UnionFind2 ; "+time2+" s");
        UnionFind3 unionFind3=new UnionFind3(size);
        double time3 = testUF(unionFind3, m);
        System.out.println("UnionFind3 ; "+time3+" s");
        UnionFind4 unionFind4=new UnionFind4(size);
        double time4 = testUF(unionFind4, m);
        System.out.println("UnionFind4 ; "+time4+" s");
        UnionFind5 unionFind5=new UnionFind5(size);
        double time5 = testUF(unionFind5, m);
        System.out.println("UnionFind5 ; "+time5+" s");
    }



}
